package com.example.lewisgao.myapplication.activity;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.lewisgao.myapplication.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.rey.material.app.ToolbarManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by LewisGao on 2015-07-01 0001.
 */
public class PlanListActivity extends ActionBarActivity {

    @ViewInject(R.id.mainToolbar)
    private Toolbar mToolbar;

    private ToolbarManager mToolbarManager;

    @ViewInject(R.id.planList)
    private ListView planList;

    private SimpleAdapter simpleAdapter;
    private List<Map<String, Object>> dataList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.plan_list);
        ViewUtils.inject(this);
        mToolbar.setTitle(getString(R.string.planManagement));
//        setSupportActionBar(mToolbar);
        mToolbarManager = new ToolbarManager(this, mToolbar, 0, R.style.ToolbarRippleStyle, R.anim.abc_fade_in, R.anim.abc_fade_out);
//        mToolbarManager.setNavigationManager(new ToolbarManager.BaseNavigationManager(R.style.NavigationDrawerDrawable, this, mToolbar, dl_navigator) {
//            @Override
//            public void onNavigationClick() {
//                if(mToolbarManager.getCurrentGroup() != 0)
//                    mToolbarManager.setCurrentGroup(0);
//                else
//                    dl_navigator.openDrawer(Gravity.START);
//            }
//
//            @Override
//            public boolean isBackState() {
//                return super.isBackState() || mToolbarManager.getCurrentGroup() != 0;
//            }
//
//            @Override
//            protected boolean shouldSyncDrawerSlidingProgress() {
//                return super.shouldSyncDrawerSlidingProgress() && mToolbarManager.getCurrentGroup() == 0;
//            }
//
//        });
        dataList = new ArrayList<>();
        simpleAdapter = new SimpleAdapter(this, getData(), R.layout.plan_list_item, new String[]{"project", "period", "state"}, new int[]{R.id.project, R.id.period, R.id.state});
        planList.setAdapter(simpleAdapter);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        mToolbarManager.createMenu(R.menu.menu_main);
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        mToolbarManager.onPrepareMenu();
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
//        switch (item.getItemId()) {
//            case R.id.tb_contextual:
//                mToolbarManager.setCurrentGroup(R.id.tb_group_contextual);
//                break;
//            case R.id.tb_done:
//            case R.id.tb_done_all:
//                mToolbarManager.setCurrentGroup(0);
//                break;
//        }
        return true;
    }


    private List<Map<String, Object>> getData() {
        for (int i = 0; i < 20; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("project", "项目"+i);
            map.put("period", "第201501" + i+"期");
            map.put("state", "未下载");
            dataList.add(map);
        }
        return dataList;
    }
}
